package com.lds.offer.demo;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @description: 剑指 Offer 61. 扑克牌中的顺子
 * @author: lds
 * @create: 2022-10-06 15:11
 **/
public class Offer_61_扑克牌中的顺子 {

    //https://leetcode.cn/problems/bu-ke-pai-zhong-de-shun-zi-lcof/

    /**
     * 关键点max-min<5为顺子
     *
     */
    public static void main(String[] args) {
        int[] arr = new int[] {0,0,0,0,5};
        boolean shunZi = isShunZi(arr);
        System.out.println(shunZi);
    }

    public static boolean isShunZi(int[] arr) {
        Set repeat = new HashSet();
        int max = 0;
        int min = 256;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == 0) {
                continue;
            }
            if (repeat.contains(arr[i])) {
                return false;
            }
            max = Math.max(max,arr[i]);
            min = Math.min(min,arr[i]);
            repeat.add(arr[i]);
        }
        return max-min < 5;
    }
}
